package cn.chencq.sort;

import java.util.Arrays;

public class InsertSort {

	public static void sort(int arr[]) {
		int len = arr.length;
		int i, j;
		for (i = 0; i < len - 1; i++) {
			int tmp = arr[i + 1];
			j = i;
			while (j > -1 && tmp <= arr[j]) {
				arr[j + 1] = arr[j];
				j--;
			}
			arr[j + 1] = tmp;
			System.out.println(Arrays.toString(arr));
		}
	}
	
	public static void main(String[] args) {
		int[] arr = {7, 5, 2, 4, 8, 2, 1, 3};
		InsertSort.sort(arr);
	}

}
